package com.vegetable.modules.service.stock.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vegetable.common.utils.PageUtils;
import com.vegetable.modules.entity.stock.CostWeightChangeSource;
import com.vegetable.modules.mapper.stock.CostWeightChangeSourceMapper;
import com.vegetable.modules.service.stock.ICostWeightChangeSourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 成本单价变化源头记录 服务实现类
 * </p>
 *
 * @author wangruijie
 * @since 2024-03-21
 */
@Slf4j
@Service
public class CostWeightChangeSourceServiceImpl extends ServiceImpl<CostWeightChangeSourceMapper, CostWeightChangeSource> implements ICostWeightChangeSourceService {
    
    @Override
    public IPage<CostWeightChangeSource> queryPage(QueryWrapper<CostWeightChangeSource> queryWrapper, Long page, Long limit) {
        log.info("分页查询成本单价变化记录，page: {}, limit: {}", page, limit);
        
        try {
            Page<CostWeightChangeSource> pageObj = new Page<>(page, limit);
            pageObj = this.page(pageObj, queryWrapper);
            
            PageUtils pageUtils = new PageUtils(pageObj);
            log.info("分页查询完成，总记录数: {}", pageUtils.getTotalCount());
            
            return pageObj;
        } catch (Exception e) {
            log.error("分页查询成本单价变化记录时发生错误", e);
            throw new RuntimeException("分页查询失败: " + e.getMessage(), e);
        }
    }
}